import request from './index' // 导入你的请求封装

// 扩展String原型,添加请求方法
declare global {
  interface String {
    get<T = any>(params?: Record<string, any>, config?: Partial<AxiosConfig>): Promise<T>
    post<T = any>(data?: Record<string, any>, config?: Partial<AxiosConfig>): Promise<T>
    put<T = any>(data?: Record<string, any>, config?: Partial<AxiosConfig>): Promise<T>
    delete<T = any>(params?: Record<string, any>, config?: Partial<AxiosConfig>): Promise<T>
  }
}

String.prototype.get = function <T = any>(
  params?: Record<string, any>,
  config?: Partial<AxiosConfig>
) {
  return request.get<T>({
    url: this as string,
    params,
    ...config
  })
}

String.prototype.post = function <T = any>(
  data?: Record<string, any>,
  config?: Partial<AxiosConfig>
) {
  return request.post<T>({
    url: this as string,
    data,
    ...config
  })
}

String.prototype.put = function <T = any>(
  data?: Record<string, any>,
  config?: Partial<AxiosConfig>
) {
  return request.put<T>({
    url: this as string,
    data,
    ...config
  })
}

String.prototype.delete = function <T = any>(
  params?: Record<string, any>,
  config?: Partial<AxiosConfig>
) {
  return request.delete<T>({
    url: this as string,
    params,
    ...config
  })
}
